#include <windows.h>

#include <memory>
#include <tuple>
#include <vector>
#include "include/esgSet.h"
#include <iostream>

using namespace std;

namespace cudaEsg
{
	

	float* ESGSet::GetMatrix(int matrixId) const
	{
		auto iterator = weightsMatrices->begin();
		for (; iterator != weightsMatrices->end(); ++iterator)
		{
			if (get<0>(*iterator) == matrixId)
				return get<1>(*iterator);
		}
		return nullptr;
	}

	void ESGSet::AddMatrix(int matrixId, float* matrixAddress, unsigned char* profileFlags) const
	{
		weightsMatrices->push_back(make_tuple(matrixId, matrixAddress));
		profiles->push_back(make_tuple(matrixId, profileFlags));
	}

	void ESGSet::AddIssuesWeights(int matrixId, float* weights) const
	{
		issueWeights->push_back(make_tuple(matrixId, weights));
	}

	unsigned char*  ESGSet::GetProfiles(int matrixId) const
	{
		auto iterator = profiles->begin();
		for (; iterator != profiles->end(); ++iterator)
		{
			if (get<0>(*iterator) == matrixId)
				return get<1>(*iterator);
		}
		return nullptr;
	}

	float* ESGSet::GetIssuesWeights(int matrixId) const
	{
		auto iterator = issueWeights->begin();
		for (; iterator != issueWeights->end(); ++iterator)
		{
			if (get<0>(*iterator) == matrixId)
				return get<1>(*iterator);
		}
		return nullptr;
	}

	float* ESGSet::GetCombinationModifier(int matrixId) const
	{
		auto iterator = modifiers->begin();
		for (; iterator != modifiers->end(); ++iterator)
		{
			if (get<0>(*iterator) == matrixId)
				return get<1>(*iterator);
		}
		return nullptr;
	}

	void ESGSet::AddCombinationModifiers(int matrixId, float* modifiers) const
	{
		this->modifiers->push_back(make_tuple(matrixId, modifiers));

	}

	unsigned char* ESGSet::GetUniverse(int universeId) const
	{
		auto iterator = universes->begin();
		for (; iterator != universes->end(); ++iterator)
		{
			if (get<0>(*iterator) == universeId)
				return get<1>(*iterator);
		}
		return nullptr;
	}

	void ESGSet::AddUniverse(int universeId, unsigned char* universeAddress) const
	{
		universes->push_back(make_tuple(universeId, universeAddress));
	}


	ESGSet::ESGSet() :ESGSet(0,0)
	{
		
	}

	ESGSet::ESGSet(int setId,int companiesCount) 
	{
		this->id = setId;
		this->companiesCount = companiesCount;
		universes = new vector<tuple<int, unsigned char*>>();
		profiles = new vector<tuple<int, unsigned char*>>();
		weightsMatrices = new vector<tuple<int, float*>>();
		modifiers = new vector<tuple<int, float*>>();
		issueWeights = new vector<tuple<int, float*>>();
	}

	ESGSet::~ESGSet()
	{
	std:cout << "destructor";

	
	}
};